﻿#region File Description
//-----------------------------------------------------------------------------
// GalaxyComponent.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion


namespace FUSE
{
    /// <summary>
    /// Galaxy Component (Abstract Object)
    ///  all object stored in galaxy map with exception of the ship should inherit properties from galaxy component
    ///  galaxy map’s collection array should store each of the objects as galaxy components
    ///  Galaxy Component Requirements
    /// </summary>
    public abstract class GalaxyComponent
    {

        /// <summary>
        /// Name of the galaxy component
        /// </summary>
        String name = "unknown Component";
        Texture2D componentTexture;
        Circle componentBounds;

        Vector2 renderPosition;
        Vector2 centerPosition;         //needs to be calculated on creation ESSENTIAL to distance calcs
        

        //Vector2 collisionArea;
        //Vector2 destination;


        /// <summary>
        /// Creates a new shape. Calls the virtual Create method to generate any vertex buffers etc
        /// </summary>
        public GalaxyComponent()
        {
            componentBounds = new Circle();

            renderPosition = new Vector2();
            centerPosition = new Vector2();
        }

        public void Initialize()
        {
            componentBounds.SetPosition(Vector2.Zero);
            componentBounds.radius = 0;
            renderPosition = Vector2.Zero;
            centerPosition = Vector2.Zero;
        }

        public void LoadContent(Texture2D newTexture)
        {
            componentTexture = newTexture;
            centerPosition = new Vector2((newTexture.Width / 2), (newTexture.Height / 2));
            componentBounds.SetPosition(centerPosition);
            componentBounds.radius = Math.Max(newTexture.Height / 2, newTexture.Width / 2);
            
        }
        
        public void SetRenderPosition(float xCoord, float yCoord)
        {

        }

        public void SetCenterPosition(float xCoord, float yCoord)
        {

        }

        /// <summary>
        /// Updates the shape. Base class does nothing
        /// </summary>
        /// <param name="time">Game Time</param>
        public void Update(GameTime gameTime)
        {
            //Nothing for now
        }

        public double distance(Vector2 otherPosition)
        {
            double dist = 0;
            dist = Math.Sqrt((centerPosition.X - otherPosition.X) * 
                (centerPosition.X - otherPosition.X) + (centerPosition.Y - otherPosition.Y) * 
                (centerPosition.Y - otherPosition.Y));
            return dist;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(componentTexture, renderPosition, Color.White); 
        }

    }
}
